﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YunShop_WebAPI.BLL
{
    public class Utils
    {
        public static ArrayList HashtableToArrayList(Hashtable ht)
        {
            ArrayList arrayList = new ArrayList();
            try
            {
                arrayList.Add(ht);
            }
            catch
            {            
            }
            return arrayList;
        }

        /// <summary>
        /// 根据记录数计算页数
        /// </summary>
        /// <param name="count"></param>
        /// <param name="page_size"></param>
        /// <returns></returns>
        public static int GetPageCount(int count, int page_size)
        {
            if (page_size == 0) return count;
            int page_count = count % page_size == 0 ? count / page_size : (count / page_size) + 1;
            return page_count;
        }

        /// <summary>
        /// 生成19位数字编码
        /// </summary>
        public static long GetGuidIntID()
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            return BitConverter.ToInt64(buffer, 0);
        }

        /// <summary>
        /// 返回文件扩展名不含<.>
        /// </summary>
        /// <param name="file_path">文件全名称</param>
        /// <returns>string</returns>
        public static string GetFileExt(string file_path)
        {
            if (string.IsNullOrEmpty(file_path)) return string.Empty;
            //文件扩展名不含<.>
            if (file_path.LastIndexOf(".") > 0) return file_path.Substring(file_path.LastIndexOf(".") + 1);
            return string.Empty;
        }

    }
}
